package com.liveinstars.activity.business.activity.repository.persistence;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.liveinstars.activity.business.activity.repository.po.Activity;
import com.liveinstars.activity.business.activity.repository.mapper.ActivityMapper;
import com.liveinstars.activity.business.activity.repository.facade.IActivityService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.liveinstars.api.query.ActivityNewQuery;
import com.liveinstars.api.query.ActivityNewQuery;
import com.onepiece.shipelves.common.enums.SystemExceptionEnum;
import com.onepiece.shipelves.common.exception.DatabaseException;
import org.springframework.stereotype.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author ting
 * @since 2020-08-24
 */
@Service
public class ActivityServiceImpl extends ServiceImpl<ActivityMapper, Activity> implements IActivityService {

    private final static Logger logger = LoggerFactory.getLogger(ActivityServiceImpl.class);
    @Resource
    private ActivityMapper activityMapper;

//    @Override
//    public IPage<Activity> pageByQuery(ActivityNewQuery query) {
//
//        try {
//            Page<Activity> page = new Page<>(query.getPageNum(), query.getPageSize());
//            QueryWrapper<Activity> queryWrapper = constructQueryWrapperByQuery(query);
//            queryWrapper.orderByDesc("id");
//            this.page(page, queryWrapper);
//            return page;
//        } catch (Exception e) {
//            logger.error("获取举报记录分页列表异常：{}", e.getMessage(), e);
//            throw new DatabaseException(SystemExceptionEnum.MYSQL_OPERATING_ERROR);
//        }
//    }

    @Override
    public IPage<Activity> pageByQuery(ActivityNewQuery query) {
        List<Activity> activities = this.activityMapper.pageByQuery((query.getPageNum() - 1) * query.getPageSize(), query.getPageSize(), query.getInterestId()
                , query.getIsCompany(), query.getIsOnline(), query.getIds(), query.getSmallGroupIds(), query.getSearchWord(), query.getType(), query.getGroupIds(),
                query.getStatus(), query.getUserId());
        Page<Activity> page = new Page<>(query.getPageNum(), query.getPageSize());
        page.setRecords(activities);
        return page;
    }

    @Override
    public IPage<Activity> pageByNewQueryIds(ActivityNewQuery query) {
        List<Activity> activities = this.activityMapper.pageByNewQuery((query.getPageNum() - 1) * query.getPageSize(), query.getPageSize(), query.getInterestId()
                , query.getIsCompany(), query.getIsOnline(), query.getIds(), query.getSmallGroupIds(), query.getSearchWord(), query.getType(), query.getGroupIds());
        Page<Activity> page = new Page<>(query.getPageNum(), query.getPageSize());
        page.setRecords(activities);
        return page;
    }


}
